/*
 * @Author: Liang 1931226988@qq.com
 * @Date: 2023-08-19 14:37:53
 * @LastEditors: Liang 1931226988@qq.com
 * @LastEditTime: 2023-08-19 15:28:25
 * @FilePath: \WanYi\src\utils\request.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
class Serve {
  api(params: any) {
    return new Promise((resolve, reject) => {

      uni.request({
        url: params.url,
        method: params.method || "GET",
        timeout: 5000,
        data: params.data || {},
        success(res) {
          resolve(res.data);
        },
        fail(error) {
          reject(error);
        },
        complete() {
          // 不管成功还是失败都结束提示
          uni.hideLoading();
        },
      });
    });
  }

  get(params: any) {
    params.method = "GET";
    return this.api(params);
  }

  post(params: any) {
    params.method = "POST";
    return this.api(params);
  }

  delete(params: any) {
    params.method = "DELETE";
    return this.api(params);
  }
}

export default Serve
